package com.ymatou.iapi.pushbind.testcase;

import com.ymatou.iapi.pushbind.parameter.SaveSellerPushConfigBean;
import com.ymatou.iapi.pushbind.parameter.SellerPushConfig;
import com.ymatou.iapi.pushbind.service.SaveSellerPushConfigCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import com.ymttest.utils.YMTDateUtil;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.util.Map;
import java.util.Random;

/**
*保存买手推送配置
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SaveSellerPushConfig{
	private static SaveSellerPushConfigBean savesellerpushconfigBean;
	private static SaveSellerPushConfigCall savesellerpushconfigCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("保存买手推送配置");
	}

	@Before
	public void caseUp() {
		savesellerpushconfigBean=new SaveSellerPushConfigBean();
		savesellerpushconfigCall=new SaveSellerPushConfigCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(savesellerpushconfigCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SaveSellerPushConfig_001() {
		Logger.start(true,"保存买手推送配置");
		try {
			int userid = new Random().nextInt(10000);
			String clientId = "Test" + YMTDateUtil.getDate();
			SellerPushConfig sellerPushConfig = new SellerPushConfig();
			sellerPushConfig.setUserId(userid);
			sellerPushConfig.setClientId(clientId);
			sellerPushConfig.setInteractiveMsgSwitch(1);
			sellerPushConfig.setOrderStatusSwitch(1);
			sellerPushConfig.setOrderUnPaySwitch(1);
			sellerPushConfig.setSocialMessageSwitch(1);
			sellerPushConfig.setTransactionSwitch(1);
			savesellerpushconfigBean.setConfigInfo(sellerPushConfig);
			savesellerpushconfigCall.setData(savesellerpushconfigBean);
			savesellerpushconfigCall.callService();
			ImDefaultWapper im = new ImDefaultWapper();
			Logger.verifyEquals("200",savesellerpushconfigCall.getString("Status"),"验证Status");
			Map map = im.selectSellerPushConfigByUserId(userid).get(0);
			Logger.debug(map);
			Logger.verifyEquals(userid,Integer.parseInt(map.get("UserId").toString()),"验证UserId");
			Logger.verifyEquals(savesellerpushconfigBean.getConfigInfo().getClientId().toString(),map.get("ClientId").toString(),"验证ClientId");
			Logger.verifyEquals(savesellerpushconfigBean.getConfigInfo().getOrderStatusSwitch().toString(),map.get("OrderStatusSwitch").toString(),"验证OrderStatusSwitch");
			Logger.verifyEquals(savesellerpushconfigBean.getConfigInfo().getTransactionSwitch().toString(),map.get("TransactionSwitch").toString(),"验证TransactionSwitch");
			Logger.verifyEquals(savesellerpushconfigBean.getConfigInfo().getSocialMessageSwitch().toString(),map.get("SocialMessageSwitch").toString(),"验证SocialMessageSwitch");
			Logger.verifyEquals(savesellerpushconfigBean.getConfigInfo().getOrderUnPaySwitch().toString(),map.get("OrderUnPaySwitch").toString(),"验证OrderUnPaySwitch");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SaveSellerPushConfig_002() {
		Logger.start(true,"保存买手推送配置,修改保存配置");
		try {
			int userid = new Random().nextInt(10000);
			String clientId = "Test" + YMTDateUtil.getDate();
			SellerPushConfig sellerPushConfig = new SellerPushConfig();
			sellerPushConfig.setUserId(userid);
			sellerPushConfig.setClientId(clientId);
			sellerPushConfig.setInteractiveMsgSwitch(1);
			sellerPushConfig.setOrderStatusSwitch(1);
			sellerPushConfig.setOrderUnPaySwitch(1);
			sellerPushConfig.setSocialMessageSwitch(1);
			sellerPushConfig.setTransactionSwitch(1);
			savesellerpushconfigBean.setConfigInfo(sellerPushConfig);
			savesellerpushconfigCall.setData(savesellerpushconfigBean);
			savesellerpushconfigCall.callService();
			Logger.verifyEquals("200",savesellerpushconfigCall.getString("Status"),"验证Status");
			ImDefaultWapper im = new ImDefaultWapper();
			Map map = im.selectSellerPushConfigByUserId(userid).get(0);
			Logger.debug(map);
			Logger.verifyEquals(userid,Integer.parseInt(map.get("UserId").toString()),"验证UserId");
			Logger.verifyEquals(savesellerpushconfigBean.getConfigInfo().getClientId().toString(),map.get("ClientId").toString(),"验证ClientId");
			Logger.verifyEquals(savesellerpushconfigBean.getConfigInfo().getOrderStatusSwitch().toString(),map.get("OrderStatusSwitch").toString(),"验证OrderStatusSwitch");
			Logger.verifyEquals(savesellerpushconfigBean.getConfigInfo().getTransactionSwitch().toString(),map.get("TransactionSwitch").toString(),"验证TransactionSwitch");
			Logger.verifyEquals(savesellerpushconfigBean.getConfigInfo().getSocialMessageSwitch().toString(),map.get("SocialMessageSwitch").toString(),"验证SocialMessageSwitch");
			Logger.verifyEquals(savesellerpushconfigBean.getConfigInfo().getOrderUnPaySwitch().toString(),map.get("OrderUnPaySwitch").toString(),"验证OrderUnPaySwitch");
			sellerPushConfig.setSocialMessageSwitch(0);
			sellerPushConfig.setTransactionSwitch(0);
			savesellerpushconfigCall.callService();
			map = im.selectSellerPushConfigByUserId(userid).get(0);
			Logger.verifyEquals(userid,Integer.parseInt(map.get("UserId").toString()),"验证UserId");
			Logger.verifyEquals(savesellerpushconfigBean.getConfigInfo().getClientId().toString(),map.get("ClientId").toString(),"验证ClientId");
			Logger.verifyEquals(savesellerpushconfigBean.getConfigInfo().getOrderStatusSwitch().toString(),map.get("OrderStatusSwitch").toString(),"验证OrderStatusSwitch");
			Logger.verifyEquals(savesellerpushconfigBean.getConfigInfo().getTransactionSwitch().toString(),map.get("TransactionSwitch").toString(),"验证TransactionSwitch");
			Logger.verifyEquals(savesellerpushconfigBean.getConfigInfo().getSocialMessageSwitch().toString(),map.get("SocialMessageSwitch").toString(),"验证SocialMessageSwitch");
			Logger.verifyEquals(savesellerpushconfigBean.getConfigInfo().getOrderUnPaySwitch().toString(),map.get("OrderUnPaySwitch").toString(),"验证OrderUnPaySwitch");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SaveSellerPushConfig_003() {
		Logger.start(true,"保存买手推送配置,userId为空");
		try {
			String clientId = "Test" + YMTDateUtil.getDate();
			SellerPushConfig sellerPushConfig = new SellerPushConfig();
			sellerPushConfig.setClientId(clientId);
			sellerPushConfig.setInteractiveMsgSwitch(1);
			sellerPushConfig.setOrderStatusSwitch(1);
			sellerPushConfig.setOrderUnPaySwitch(1);
			sellerPushConfig.setSocialMessageSwitch(1);
			sellerPushConfig.setTransactionSwitch(1);
			savesellerpushconfigBean.setConfigInfo(sellerPushConfig);
			savesellerpushconfigCall.setData(savesellerpushconfigBean);
			savesellerpushconfigCall.callService();
			Logger.verifyEquals("406",savesellerpushconfigCall.getString("Status"),"验证Status，参数错误");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}